//
//  VLCMedia.swift
//  yiplayer
//
//  Created by wkun on 2024/6/17.
//

import Foundation
import MobileVLCKit
import SMBClient

class VLCMediaCtrl : UIViewController {
    
    var filePath: String?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.view.backgroundColor = .black
        
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
//        "smb://cgw:htc@192.168.1.103/cgw/Desktop/1yinyuehui/王杰/mv/4k修复王杰《回家》-威武神经-BV1SL411Q7wx-HaykPn6z1DGmEh8q/4k修复王杰《回家》-威武神经-BV1SL411Q7wx-HaykPn6z1DGmEh8q.mp4"
//        let pa = "smb://cgw:htc@192.168.1.103/cgw/Desktop/f6.mp4"
        //let pa = self.filePath
        let pa = "smb://wkun:1212@192.168.0.101/workspace1111/course/ff.mp4"
        self.play_vlc(path: pa)
        
        let closeBtn = Button.str("关闭").color(ColorF)
        closeBtn.frame = .init(x: 0, y: 0, width: 50, height: 50)
        closeBtn.onTap {
            self.dismiss(animated: true)
        }
        self.view.addSubview(closeBtn)
    }
    
    let player = VLCMediaPlayer()
    func play_vlc(path: String?) {
        if let path = path {
            player.drawable = self.view;
            
            if let encodedUrlString = path.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
                if let url = URL(string: encodedUrlString) {
                    let media = VLCMedia(url: url)
                    player.media = media
                    player.play()
                    return
                }
            }
            
            printLog("播放失败, url问题")
        }
    }
}
